<template>
  <div id="app">
    <el-menu
      :default-active="activeIndex"
      class="el-menu-demo"
      mode="horizontal"
      @select="handleSelect"
      background-color="#545c64"
      text-color="#fff"
      active-text-color="#ffd04b"
      v-if="this.$route.meta.showNav"
    >
      <el-submenu index="1">
        <template slot="title">病床数据</template>
        <el-menu-item index="1-1" @click="index">病床统计</el-menu-item>
        <el-menu-item index="1-2" @click="sickbedList">病床列表</el-menu-item>
      </el-submenu>

      <el-submenu index="2" v-if="adminPosition == 1 || adminPosition == 2 || adminPosition == 4">
        <template slot="title">就诊管理</template>
        <el-menu-item
          index="2-1"
          @click="addPatient"
          v-if="adminPosition == 1 || adminPosition == 2"
        >门诊导诊</el-menu-item>
        <el-menu-item
          index="3-2"
          @click="docDia"
          v-if="adminPosition == 1 || adminPosition == 4"
        >医生诊断</el-menu-item>
      </el-submenu>
      <el-submenu index="4" v-if="adminPosition == 1 || adminPosition == 2">
        <template slot="title">出入科管理</template>
        <el-menu-item index="4-1" @click="inHospitalManage">入科管理</el-menu-item>
        <el-menu-item index="4-3" @click="leaveHospital">出科管理</el-menu-item>
      </el-submenu>
      <el-submenu index="7" v-if="adminPosition == 1">
        <template slot="title">帐号管理</template>
        <el-menu-item index="7-1" @click="register">员工注册</el-menu-item>
        <el-menu-item index="7-2" @click="accountManage">员工账号管理</el-menu-item>
      </el-submenu>
      <el-submenu index="9" v-if="adminPosition == 1">
        <template slot="title">小程序管理</template>
        <el-menu-item index="9-1" @click="swiperManage">轮播图管理</el-menu-item>
        <el-menu-item index="9-2" @click="articleManage">医院资讯管理</el-menu-item>
        <el-menu-item index="9-3" @click="noticleManage">消息管理</el-menu-item>
      </el-submenu>
      <el-menu-item index="10" v-if="adminPosition == 1 || adminPosition == 4">在线问诊</el-menu-item>
      <el-submenu index="11" class="user">
        <template slot="title">
          <i class="el-icon-user"></i>
          {{ adminName + "-" +positionName }}
        </template>
        <el-menu-item index="11-1" @click="user">个人中心</el-menu-item>
        <el-menu-item index="11-2" @click="quit">退出登陆</el-menu-item>
      </el-submenu>
    </el-menu>

    <router-view @adminApp="adminApp" :adminName="adminName" />
  </div>
</template>

<script>
export default {
  name: "App",
  data() {
    return {
      activeIndex: "1",
      adminName: "",
      adminPosition: "",
      positionName: ""
    };
  },
  methods: {
    handleSelect() {},
    index() {
      this.$router.push("/index");
    },
    sickbedList() {
      this.$router.push("/sickbedList");
    },
    register() {
      this.$router.push("/register");
    },
    accountManage() {
      this.$router.push("/accountManage");
    },
    sickbed() {
      this.$router.push("/sickbedManage");
    },
    addPatient() {
      this.$router.push("/addPatient");
    },
    docDia() {
      this.$router.push("/docDia");
    },
    inHospitalManage() {
      this.$router.push("/inHospitalManage");
    },
    leaveHospital() {
      this.$router.push("/leaveHospitalManage");
    },
    swiperManage() {
      this.$router.push("/swiperManage");
    },
    articleManage() {
      this.$router.push("/articleManage");
    },
    noticleManage() {
      this.$router.push("/noticleManage");
    },
    user() {
      this.$router.push("/user");
    },
    adminApp(res) {
      this.adminName = res.adminName;
      this.positionName = res.position;
      if (res.position == "管理员") {
        this.adminPosition = 1;
      } else if (res.position == "前台管理") {
        this.adminPosition = 2;
      } else if (res.position == "护士") {
        this.adminPosition = 3;
      } else if (res.position == "医生") {
        this.adminPosition = 4;
      }
    },
    quit() {
      this.adminName = "";
      this.adminPosition = "";
      this.$router.push("/");
      this.$message({
        message: "退出登陆成功",
        type: "success"
      });
    }
  }
};
</script>

<style>
.user {
  position: absolute;
  right: 10px;
}

html,
body,
#app {
  height: 100%;
  margin: 0;
}
</style>
